package com.jianglin.state2.core;

import com.jianglin.state2.dao.entity.Employee;
import com.jianglin.state2.service.EmployeeService;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@ApiModel("响应包装")
public class ResponseObj implements Serializable {
    private static final long serialVersionUID =1L;
    /**
     * 请求结果
     */
    @ApiModelProperty("code")
    private Integer code;
    /**
     * 认证结果
     */
    @ApiModelProperty("信息")
    private String msg;
    /**
     * 错误信信
     */
    @ApiModelProperty("数量")
    private Integer count;
    /**
     * 请求成功返回的数据
     */
    @ApiModelProperty("请求成功时的数据")
    private Object data;

    /**
     * 请求成功
     *
     * @param data 成功时的数据
     * @return 返回响应对象
     */
    public static ResponseObj success(Object data) {
        return builder()
                .code(0)
                .msg("")
                .count(1000)
                .data(data)
                .build();
    }

    /**
     * 请求失败
     *
     * @param errorMsg 失败信息
     * @return 返回响应对象
     */
    public static ResponseObj fail(String errorMsg) {
        return builder()
                .code(1)
                .msg("")
                .count(0)
                .data(null)
                .build();
    }

}
